package string

import (
	"fmt"
	"regexp"
)

func TestRegExp() {
	var s = "djfghsdghk uidjghiur fgir    ugfyehrdfog   iodgrifhg"

	exp, err := regexp.Compile("\\W+")
	if err != nil {
		fmt.Println("err := " + err.Error())
		return
	}

	//正则表达式分隔
	slice := exp.Split(s, -1)
	for _, value := range slice {
		fmt.Println(value)
	}

	exp2, _ := regexp.Compile("[0-9]+")
	s2 := "dsgfd454rjgfuy465yftiujgyu43j6554giugruei6576"

	fmt.Println(exp2.FindAllString(s2, -1))
	fmt.Println(exp2.FindAllStringIndex(s2, -1))

	fmt.Println(exp2.FindAll([]byte(s2), -1))
	fmt.Println(exp2.FindAllIndex([]byte(s2), -1))

	//获取第一个字符串
	fmt.Println(exp2.FindString(s2))
	fmt.Println(exp2.FindStringIndex(s2))

	//获取第一个[]byte
	fmt.Println(exp2.Find([]byte(s2)))
	fmt.Println(exp2.FindIndex([]byte(s2)))

}
